const express = require('express')
const app = express()
// 环境变量
const envconfig=require('./envConfig')
envconfig()
const bodyParser = require('body-parser')
const cors = require('cors')
const ipv4 = require('./util/IPv4.js')
const port = 8089
app.listen(port, () => console.log(`服务启动成功: => http://localhost:${port}
ipv4: => http://${ipv4()}:${port} `))
app.use(express.static('apidoc'))
app.use(express.static('public'))
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use(cors({ origin: '*' }))
app.get('/', (req, res, neth) => res.send('node-server'))
app.use(require('./util/frontMiddleware.js'))
app.use('/v1/user', require('./router/userinfo.js'))
app.use('/v1/opinion', require('./router/opinionAdmin.js'))
app.use('/v1', require('./router/public.js'))
app.use((req, res, neth) => res.sendform(404, '你访问的资源不存在'))
app.use((err, req, res, neth) => res.sendform(500, err.message))